package com.fit.pages;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;


import com.fit.beans.DamageBean;
import com.fit.interfaces.Damage;
import com.fit.interfaces.RecordDamage;
import com.fit.interfaces.User;
import com.fit.service.Damages;
import com.fit.service.RecordDamages;

public class EntryDamage {

	@SessionState
	private User user;
	
	private boolean userExists;
	
	public User getUser(){
		return user;
	}
	
	public Object onActivate(){
		if(!userExists) return Login.class;
		return null;
	}
	
	
	
	
	
	
	@Property
	@Persist
	private String name;
	
//	@SetupRender
//	public void createObject(){
//		damage.setName(name);
//	}
	
	
//	@Persist	
//	@Property
//	private RecordDamage record;
	@Property
	@InjectPage
	private ViewDamage viewDamagePage;
	
	@Property
	@Inject
	private Damages damages;
	
	
	@OnEvent
	Object onSubmit(){
		//record.setDamage(damage);
		Damage damageBean = new DamageBean();
		damageBean.executeDamageBean(name);
		damages.save(damageBean);
		return viewDamagePage;
		//record.setDamage(damage);
	}
	
}
